package com.wokeMy.view.adpter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.woke.adapter.OnItemClickListener;
import com.woke.data.UnionPayChannel;
import com.zhongcai.online.R;

import java.util.List;


/**
 * Created by Administrator on 2017-11-21.
 */

public class PassAdapter extends BaseAdapter {
    private LayoutInflater inflater;
    List<UnionPayChannel> list;
    private Context context;

    private OnItemClickListener mItemClickListener;

    public void setOnItemClickListener(OnItemClickListener listener) {
        mItemClickListener = listener;
    }
    public PassAdapter(Context context, List<UnionPayChannel> list) {
        inflater=LayoutInflater.from(context);
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
            ViewHold viewHold;
            if(convertView==null){
                viewHold=new ViewHold();
                convertView=inflater.inflate(R.layout.item_select_pass_lv,null);
                viewHold.tvTitle=(TextView)convertView.findViewById(R.id.title_item_selectpass_tv);
                viewHold.tvTishi=(TextView)convertView.findViewById(R.id.tishi_pass_iv);
                viewHold.tvEdu=(TextView)convertView.findViewById(R.id.edu_pass_tv);
                viewHold.tvpaymentdate=(TextView)convertView.findViewById(R.id.paymentdate_pass_tv);
                viewHold.message=(TextView)convertView.findViewById(R.id.message_pass_tv);
                convertView.setTag(viewHold);
            }else{
                viewHold=(ViewHold)convertView.getTag();
            }
    //        ImageView selfCard_pass_iv=(ImageView) convertView.findViewById(R.id.selfCard_pass_iv);
            if (mItemClickListener != null) {
                mItemClickListener.OnItemClick(convertView,position);
            }
            viewHold.tvTitle.setText(list.get(position).getTitle());
            viewHold.tvTishi.setText("提示:"+list.get(position).getDescribe());
            String edu=list.get(position).getMinamount()+"元～"+list.get(position).getMaxamount()+"元";
            viewHold.tvEdu.setText(edu);
            viewHold.message.setText(list.get(position).getMessage());
            switch (Integer.parseInt(list.get(position).getPaymentdate())) {
                case 0:
                    viewHold.tvpaymentdate.setText("T"+0);
                    break;
                case 1:
                    viewHold.tvpaymentdate.setText("T"+1);
                    break;
                case 2:
                    viewHold.tvpaymentdate.setText("D"+0);
                    break;
                case 3:
                    viewHold.tvpaymentdate.setText("D"+0);
                    break;
                default:
                    break;
            }

             Log.e("pass_PassAdaptergetView",list.get(position).toString());

//        if (list.get(position).getWay()==74){
//            convertView.setVisibility(View.GONE);
//        }
//        // 错误：在这里获取到的 layoutParams 可能为空，所以需要新建一个layoutParams
//        //  获取 layoutParams =null 的原因：没有viewgroup
//        // （inflate（resource，viewgroup，attachToRoot））
//        // ,或者是attachToRoot设置为null
//        ViewGroup.LayoutParams params=new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,1);
////        ViewGroup.LayoutParams params=convertView.getLayoutParams();
//        convertView.setLayoutParams(params);
////        Log.e("mUnionPayChannels",list.get(position).toString());
        return convertView;
    }

    class ViewHold{
    TextView tvTitle;
    TextView tvTishi;
    TextView tvEdu;
    TextView tvpaymentdate;
    TextView message;
    }
}
